/*
*  Copyright 2019-2025 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.bailian.rest;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.bailian.domain.EosCustomerInfoPreLog;
import me.zhengjie.modules.bailian.domain.dto.EosCustomerInfoPreLogQueryCriteria;
import me.zhengjie.modules.bailian.service.EosCustomerInfoPreLogService;
import me.zhengjie.utils.PageResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
* @author Yaco
* @date 2025-04-24
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "EOS客户信息预录表")
@RequestMapping("/api/eosCustomerInfoPreLog")
public class EosCustomerInfoPreLogController {

    private final EosCustomerInfoPreLogService eosCustomerInfoPreLogService;

    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('eosCustomerInfoPreLog:list')")
    public void exportEosCustomerInfoPreLog(HttpServletResponse response, EosCustomerInfoPreLogQueryCriteria criteria) throws IOException {
        eosCustomerInfoPreLogService.download(eosCustomerInfoPreLogService.queryAll(criteria), response);
    }

    @GetMapping
    @ApiOperation("查询EOS客户信息预录表")
    @PreAuthorize("@el.check('eosCustomerInfoPreLog:list')")
    public ResponseEntity<PageResult<EosCustomerInfoPreLog>> queryEosCustomerInfoPreLog(EosCustomerInfoPreLogQueryCriteria criteria){
        Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
        return new ResponseEntity<>(eosCustomerInfoPreLogService.queryAll(criteria,page),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增EOS客户信息预录表")
    @ApiOperation("新增EOS客户信息预录表")
    @PreAuthorize("@el.check('eosCustomerInfoPreLog:add')")
    public ResponseEntity<Object> createEosCustomerInfoPreLog(@Validated @RequestBody EosCustomerInfoPreLog resources){
        eosCustomerInfoPreLogService.create(resources);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改EOS客户信息预录表")
    @ApiOperation("修改EOS客户信息预录表")
    @PreAuthorize("@el.check('eosCustomerInfoPreLog:edit')")
    public ResponseEntity<Object> updateEosCustomerInfoPreLog(@Validated @RequestBody EosCustomerInfoPreLog resources){
        eosCustomerInfoPreLogService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除EOS客户信息预录表")
    @ApiOperation("删除EOS客户信息预录表")
    @PreAuthorize("@el.check('eosCustomerInfoPreLog:del')")
    public ResponseEntity<Object> deleteEosCustomerInfoPreLog(@ApiParam(value = "传ID数组[]") @RequestBody List<Integer> ids) {
        eosCustomerInfoPreLogService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
